package edu.hwadee.serviceImpl;

import java.util.List;

import edu.hwadee.entity.Companypaper;
import edu.hwadee.service.CompanypaperService;

public class CompanypaperServiceImpl extends BasicServiceImpl implements CompanypaperService {

	@Override
	public boolean save(Companypaper companypaper) {
		try {
			getCompanypaperDAO().save(companypaper);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@Override
	public boolean delete(Companypaper companypaper) {
		try {
			getCompanypaperDAO().delete(companypaper);
			return true;
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companypaper> search(Companypaper companypaper) {
		try {
			return (List<Companypaper>)getCompanypaperDAO().findByExample(companypaper);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public Companypaper searchById(Integer companypaperId) {
		try {
			return getCompanypaperDAO().findById(companypaperId);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}

	@Override
	public boolean update(Companypaper companypaper) {
		try {
			if(searchById(companypaper.getCompanyPaperId()) != null) {
				getCompanypaperDAO().merge(companypaper);
				return true;
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return false;
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<Companypaper> showAll() {
		try {
			return (List<Companypaper>)getCompanypaperDAO().findAll();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return null;
	}
}
